<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="活动名称" prop="promotionName">
        <el-input v-model="queryParams.promotionName" placeholder="请输入活动名称" clearable
          style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="活动状态" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.goods_promotion_status" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['store:promotion:seckill:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
          @click="handleUpdate" v-hasPermi="['store:promotion:seckill:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
          v-hasPermi="['store:promotion:seckill:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['store:promotion:seckill:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['store:promotion:seckill:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="活动编号" prop="id" width="170" align="center" />
      <el-table-column label="活动名称" prop="promotionName" :show-overflow-tooltip="true" width="150"
        align="center" />
      <el-table-column label="背景图" prop="detailAppImage" :show-overflow-tooltip="true" width="100"
        align="center">
        <template slot-scope="scope">
          <el-image style="width: 50px" :src="scope.row.detailAppImage" :preview-src-list="scope.row.detailAppImage">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="活动描述" prop="description" width="200" align="center" />
      <el-table-column label="开始时间" prop="startTime" align="center" width="160" />
      <el-table-column label="结束时间" prop="endTime" align="center" width="160" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动状态" prop="promotionStatus" align="center" width="150">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.promotion_promotion_status"
            :value="scope.row.promotionStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['store:promotion:seckill:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-pear" @click="dailyDetails(scope.row)"
           v-hasPermi="['store:promotion:seckill:section:list']">
            每日详情
          </el-button>
          <el-button type="text" icon="el-icon-tableware" size="mini"
            @click="urgentClose(scope.row)" v-hasPermi="['store:promotion:seckill:cancel']">
            紧急关闭</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改秒杀活动对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="活动名称" prop="promotionName" :show-overflow-tooltip="true">
          <el-input v-model="form.promotionName" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime" class="start">
          <el-date-picker v-model="form.startTime" type="datetime" placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss" :show-overflow-tooltip="true"
            v-if="updateTimeParagraphStatus === '新增秒杀活动'"> </el-date-picker>
          <span v-if="updateTimeParagraphStatus === '修改秒杀活动'">{{form.startTime}}</span>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker v-model="form.endTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间" :show-overflow-tooltip="true"
            v-if="updateTimeParagraphStatus === '新增秒杀活动'"> </el-date-picker>
          <span v-if="updateTimeParagraphStatus === '修改秒杀活动'">{{form.endTime}}</span>
        </el-form-item>
        <el-form-item label="价格背景图" label-width="92px">
          <div v-if="updateTimeParagraphStatus === '修改秒杀活动'">
            <input type="file" @change="requiredChange" v-show="!detailAppImageStatus">
            <img class="detailAppImage" :src="form.detailAppImage" v-show="detailAppImageStatus">
            <span @click="deletePicture" v-show="detailAppImageStatus">删除</span>
          </div>
          <div v-if="updateTimeParagraphStatus === '新增秒杀活动'">
            <input id="files" type="file" @change="requiredChange" v-show="!detailAppImageStatus">
            <img class="detailAppImage" :src="form.detailAppImage" v-show="detailAppImageStatus">
            <span @click="deletePicture" v-show="detailAppImageStatus">删除</span>
          </div>
          <!-- <el-upload action="#" list-type="picture-card" :auto-upload="false"
            :on-remove="handleRemove" :on-preview="handlePictureCardPreview" :on-change="changeImg"
            :show-overflow-tooltip="true">
            <i slot="default" class="el-icon-plus"></i>
            <div slot="file" slot-scope="{ file }">
              <img class="el-upload-list__item-thumbnail" :src="file.url" />
              <span class="el-upload-list__item-actions">
                <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                  <i class="el-icon-zoom-in"></i>
                </span>
                <span v-if="!disabled" class="el-upload-list__item-delete"
                  @click="handleRemove(file)">
                  <i class="el-icon-delete"></i>
                </span>
              </span>
            </div>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" :show-overflow-tooltip="true" />
          </el-dialog> -->
        </el-form-item>
        <el-form-item label="活动描述" prop="description">
          <el-input v-model="form.description" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 每日秒杀活动时间段  formTime  -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="每日秒杀-时间段" :visible.sync="open1">
      <el-button type="primary" @click="addEveryDayTimeParagraph" v-hasPermi="['store:promotion:seckill:section:add']">新增</el-button>
      <el-table :data="tableTime">
        <el-table-column label="编号" type="index" align="center"></el-table-column>
        <el-table-column label="ID" prop="id" align="center" width="170"></el-table-column>
        <el-table-column label="开始时间" prop="startTime" align="center" width="150"></el-table-column>
        <el-table-column label="结束时间" prop="endTime" align="center" width="150"></el-table-column>
        <el-table-column label="操作" width="360px" align="center">
          <template slot-scope="scope">
            <el-button size="mini" @click="modify(scope.row)">修改</el-button>
            <el-button size="mini" @click="deleteTimeParagraph(scope.row)" v-hasPermi="['store:promotion:seckill:section:remove']">删除</el-button>
            <el-button size="mini" @click="uploadProduct(scope.row)" v-hasPermi="['store:promotion:seckill:goods:import']">上传商品</el-button>
            <el-button size="mini" @click="commodityDetails(scope.row)" v-hasPermi="['store:promotion:promotion:goods:page']">商品详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- ↑ 具体 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="添加" :visible.sync="open2" width="400px">
      <el-form :model="formTime">
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker v-model="formTime.startTime" placeholder="选择日期时间" type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker v-model="formTime.endTime" value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime" placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button @click="open2 = false">取消</el-button>
      <el-button @click="addOrUpdateTimeParagraph">确定</el-button>
    </el-dialog>

    <!-- 确认框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="提示" :visible.sync="open3" width="400px">
      <p> 确认 {{updateTimeParagraphStatus}} 吗？ </p>
      <el-button @click="open3 = false">取消</el-button>
      <el-button @click="determineDelete">确定</el-button>
    </el-dialog>

    <!-- 上传商品 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      限购方式：PROMOTION：活动；ORDER：订单；DAY：当天
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="r + '/store/promotion/seckill/' + id + '/importData' + '?minPriceRange=' + upload.minPriceRange"
        :disabled="upload.isUploading" :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text"> 将文件拖到此处，或 <em>点击上传</em> </div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.belowOriginalPriceRangeSupport" />不导入低于原价<el-input-number v-model="upload.minPriceRange" style="width: 120px;" />%的商品
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 商品详情 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="商品详情" :visible.sync="open4" width="1300px">
      商品编码: <el-input v-model="SECKILLLISTFORM.identifier" style="width:200px" clearable></el-input>
      商品名称: <el-input v-model="SECKILLLISTFORM.goodsName" style="width:200px" clearable></el-input>
      <el-button type="danger" @click="goodsList" style="margin:0 0 20px 20px">搜索</el-button>
      <el-button type="primary" plain icon="el-icon-download" size="mini" style="margin:0 0 20px 20px"
        @click="handlePromotionGoodsExport" v-hasPermi="['store:promotion:promotion:goods:export']">导出商品
      </el-button>
      <el-table border :data="SECKILLLIST">
        <el-table-column label="排序" prop="orderNum" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.orderNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="商品编码" prop="identifier" align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column label="商品名称" prop="goodsName" align="center" width="200px" :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column label="规格" prop="simpleSpecs" align="center"> </el-table-column>
        <el-table-column label="商品原价" prop="originalPrice" align="center"></el-table-column>
        <el-table-column label="活动价" prop="price" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.price" style="width: 65px;"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="活动库存" prop="quantity" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.quantity" style="width: 65px;"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="已售数量" prop="num" align="center"></el-table-column>
        <el-table-column label="销售下限" prop="unitage" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.unitage"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="限购方式" prop="limitMode" align="center" width="130px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.limitMode" placeholder="限购方式">
              <el-option v-for="dict in dict.type.promotion_limit_mode" :key="dict.value"
                :label="dict.label" :value="dict.value" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="限购数量" prop="limitNum" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.limitNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="150px">
          <template slot-scope="scope">
            <el-button size="mini" @click="modifySeckillCommodity(scope.row)" v-hasPermi="['store:promotion:promotion:goods:edit']">修改</el-button>
            <el-button size="mini" @click="delSeckillCommodity(scope.row)" v-hasPermi="['store:promotion:promotion:goods:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="parseInt(SECKILLLISTFORM.total) >0"
        :total="parseInt(SECKILLLISTFORM.total)" :page.sync="SECKILLLISTFORM.pageNum"
        :limit.sync="SECKILLLISTFORM.pageSize" @pagination="goodsList" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listSeckill, addSeckill, updateSeckill, getSeckillTimeParagraph,
  addSeckillTimeParagraph, updateSeckillTimeParagraph, delSeckillTimeParagraph, closeActivity, uploadPicture
} from "@/api/promotion/seckill"
import { getPromotionGoodsList, updatePromotionGoods, delPromotionGoods } from "@/api/promotion/promotions.js"
import axios from "axios"
import { getToken } from "@/utils/auth"

export default {
  name: "Seckill",
  dicts: ["goods_promotion_status", "promotion_limit_mode", "promotion_promotion_status"],
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: false,
      // 非多个禁用
      multiple: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      open3: false,
      open4: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      dateRanges: [],
      id: "",
      r: process.env.VUE_APP_BASE_API,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        // url:
        //   process.env.VUE_APP_BASE_API +
        //   "/store/promotion/promotion/BARGAIN/" +
        //   this.id +
        //   "/importData"
        belowOriginalPriceRangeSupport: false,
        minPriceRange: 50,
      },
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      imageFileList: undefined,
      headers: {
        Authorization: "Bearer " + getToken(),
        "Content-Type": "multipart/form-data"
      },
      // 表单校验
      rules: {
        promotionName: [
          { required: true, message: "活动名称不能为空", trigger: "blur" }
        ],
        startTime: [
          { required: true, message: "开始时间不能为空", trigger: "blur" }
        ],
        endTime: [
          { required: true, message: "结束时间不能为空", trigger: "blur" }
        ],
        detailAppImage: [
          { required: true, message: "背景图不能为空", trigger: "blur" }
        ]
      },
      //
      tableTime: [],
      formTime: {},
      rowId: '',
      seckillId: '',
      // 新增 修改状态
      updateTimeParagraphStatus: '',
      // 确认框
      determineDeleteText: '',
      SECKILLLIST: [],
      SECKILLLISTFORM: {
        pageNum: 1,
        pageSize: 10,
        identifier: '',
        goodsName: '',
      },
      ROWS: {},
      row: {},
      seckillRow: {},
      detailAppImageStatus: false,
    };
  },
  created () {
    this.getList();
  },
  methods: {
    // 紧急关闭 活动
    urgentClose (row) {
      this.row = row
      this.updateTimeParagraphStatus = '关闭活动'
      this.open3 = true
    },
    // 每日详情 按钮
    dailyDetails (row) {
      this.row = row
      this.seckillRow = row
      this.open1 = true
      this.getEveryDayTimeParagraph()
    },
    // 查询 每日秒杀-时间段 详情
    getEveryDayTimeParagraph () {
      getSeckillTimeParagraph(this.row.id).then(res => {
        if (res.code === 200) {
          this.tableTime = res.rows
        }
      })
    },
    // 每日秒杀-时间段  新增/修改
    addEveryDayTimeParagraph () {
      this.open2 = true
      this.updateTimeParagraphStatus = '新增'
    },
    // 每日秒杀-时间段 确定
    addOrUpdateTimeParagraph () {
      // 新增
      if (this.updateTimeParagraphStatus === '新增') {
        addSeckillTimeParagraph(this.seckillRow.id, { startTime: this.formTime.startTime, endTime: this.formTime.endTime }).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("操作成功")
            this.open2 = false
            this.formTime = {}
            this.getEveryDayTimeParagraph()
          }
        })
      }
      // 修改 时间段
      if (this.updateTimeParagraphStatus === '修改') {
        updateSeckillTimeParagraph(this.row.id, this.seckillId, { startTime: this.formTime.startTime, endTime: this.formTime.endTime }).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("操作成功")
            this.open2 = false
            this.formTime = {}
            this.getEveryDayTimeParagraph()
          }
        })
      }
    },
    // 修改
    modify (row) {
      this.formTime = row
      this.open2 = true
      this.updateTimeParagraphStatus = '修改'
      this.seckillId = row.id
    },
    // 删除
    deleteTimeParagraph (row) {
      this.updateTimeParagraphStatus = '删除'
      this.seckillId = row.id
      this.open3 = true
    },
    // 上传文件 商品
    uploadProduct (row) {
      this.upload.belowOriginalPriceRangeSupport = false
      this.upload.minPriceRange = 50
      this.upload.open = true
      this.row = row;
      this.id = row.id
    },
    // 商品 详情
    commodityDetails (row) {
      this.open4 = true
      this.seckillId = row.id
      this.SECKILLLISTFORM.pageNum = 1
      this.goodsList()
    },
    // 获取数据
    goodsList () {
      getPromotionGoodsList(this.seckillId, { promotionType: 'SECKILL', ...(this.SECKILLLISTFORM) }).then(res => {
        if (res.code === 200) {
          this.SECKILLLIST = res.rows
          this.SECKILLLISTFORM.total = res.total
        }
      })
    },
    modifySeckillCommodity (row) {
      this.updateTimeParagraphStatus = '修改商品'
      this.ROWS = row
      this.open3 = true
    },
    // 删除商品
    delSeckillCommodity (row) {
      this.updateTimeParagraphStatus = '删除商品'
      this.ROWS = row
      this.open3 = true
    },
    // 确认 框
    determineDelete () {
      // 关闭 活动
      if (this.updateTimeParagraphStatus === '关闭活动') {
        if (this.row.promotionStatus === 'NEW' || this.row.promotionStatus === 'START') {
          closeActivity(this.row.id, { promotionStatus: 'CLOSE' }).then(res => {
            if (res.code === 200) {
              this.$modal.msgSuccess("操作成功")
              this.open3 = false
              this.getList();
            }
          })
        }
      }
      // 删除时间段
      if (this.updateTimeParagraphStatus === '删除') {
        delSeckillTimeParagraph(this.row.id, this.seckillId).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("操作成功")
            this.open3 = false
            this.getEveryDayTimeParagraph()
          }
        })
      }
      // 修改 商品
      if (this.updateTimeParagraphStatus === '修改商品') {
        updatePromotionGoods('SECKILL', this.seckillId, this.ROWS.id, {
          price: this.ROWS.price,
          quantity: this.ROWS.quantity,
          orderNum: this.ROWS.orderNum,
          limitMode: this.ROWS.limitMode,
          limitNum: this.ROWS.limitNum,
          unitage: this.ROWS.unitage ,
        })
          .then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("操作成功")
            this.open3 = false
            this.goodsList()
          }
        })
      }
      // 删除 商品
      if (this.updateTimeParagraphStatus === '删除商品') {
        delPromotionGoods('SECKILL', this.seckillId, this.ROWS.id).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("操作成功")
            this.open3 = false
            this.goodsList()
          }
        })
      }
    },

    // 删除图片
    deletePicture () {
      if (this.updateTimeParagraphStatus === '新增秒杀活动') {
        document.getElementById('files').value = ''
      }
      this.form.detailAppImage = ''
      this.detailAppImageStatus = false
    },
    // 上传图片
    requiredChange (e) {
      let formdata = new FormData()
      formdata.append("file", e.target.files[0])
      uploadPicture(formdata).then(res => {
        if (res.code === 200) {
          this.$modal.msgSuccess("操作成功")
          this.form.detailAppImage = res.data.url
          this.detailAppImageStatus = true
        }
      })
    },


    /** 查询角色列表 */
    getList () {
      this.loading = true;
      listSeckill(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      if (this.updateTimeParagraphStatus === '新增秒杀活动') {
        this.form.detailAppImage = ''
        document.getElementById('files').value = ''
        this.detailAppImageStatus = false
        this.form = {}
      }
    },
    // 表单重置
    reset () {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      this.menuExpand = false
      this.menuNodeAll = false
      this.deptExpand = true
      this.deptNodeAll = false
      this.form = {
        roleId: undefined,
        roleName: undefined,
        roleKey: undefined,
        roleSort: 0,
        status: "0",
        menuIds: [],
        deptIds: [],
        menuCheckStrictly: true,
        deptCheckStrictly: true,
        remark: undefined
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.roleId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 更多操作触发
    handleCommand (command, row) {
      switch (command) {
        case "handleDataScope":
          this.handleDataScope(row);
          break;
        case "handleAuthUser":
          this.handleAuthUser(row);
          break;
        default:
          break;
      }
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.updateTimeParagraphStatus = '新增秒杀活动'
      this.detailAppImageStatus = false
      this.form = {}
      this.title = "添加秒杀活动";
      this.open = true;
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.form = row
      this.form.detailAppImage = row.detailAppImage
      this.detailAppImageStatus = true
      this.updateTimeParagraphStatus = '修改秒杀活动'
      this.title = "修改角色"
      this.open = true
    },
    /** 提交按钮 */
    submitForm: function () {
      if (this.updateTimeParagraphStatus === '修改秒杀活动') {
        updateSeckill(this.form.id, this.form).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("修改成功")
            this.open = false
            this.getList()
          }
        })
      } else {
        addSeckill(this.form).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("新增成功")
            this.open = false
            this.getList()
          }
        })
      }
    },
    /** 下载模板操作 */
    importTemplate () {
      this.download("store/promotion/seckill/goods/importTemplate", {}, `导入秒杀商品模板_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}{i}{s}")}.xlsx`)
    },
    // 提交上传文件
    submitFileForm () {
      if(!this.upload.belowOriginalPriceRangeSupport){
        this.$modal.msgError("请勾选促销价限制条件");
        return;
      }
      if(this.upload.minPriceRange <= 0){
        this.$modal.msgError("促销价限制条件不能小于等于0");
        return;
      }

      this.$refs.upload.submit()
    },
    // 文件上传中处理
    handleFileUploadProgress (event, file, fileList) {
      this.upload.isUploading = true;
      console.log("event", event);
    },
    // 文件上传成功处理
    handleFileSuccess (response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    /** 导入按钮操作 */
    handleImport () {
      this.upload.title = "秒杀商品导入";
      this.upload.open = true;
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        "store/promotion/promotion/goods/importTemplate",
        { ...this.queryParams },
        `导出秒杀商品_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}{i}{s}")}.xlsx`
      );
    },
    // 删除图片
    handleRemove (file, fileList) {
      const ul = document.querySelector(".el-upload-list--picture-card");
      ul.removeChild(ul.children[0]);
      ul.nextSibling.style.display = "block";
      console.log(file, fileList);
    },
    // 预览图片
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.raw.url;
      this.dialogVisible = true;
    },
    //   上传图片
    changeImg (file, fileList) {
      const ul = document.querySelector(".el-upload-list--picture-card");
      ul.nextSibling.style.display = "none";
      console.log(file, fileList);
      this.imageFileList = fileList;
    },
    handlePromotionGoodsExport () {
      this.download('store/promotion/promotion/' + this.seckillId + '/export?promotionType=SECKILL&identifier=' + this.SECKILLLISTFORM.identifier + '&goodsName=' + this.SECKILLLISTFORM.goodsName, {
        ...this.addDateRangeWithMap(this.addDateRangeWithMap(this.queryParams, this.dateRange, "CreateTime"), this.payDateRange, "PaymentTime")
      }, `秒杀商品列表_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}{i}{s}")}.xlsx`)
    },
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  top: 20px;
}
.detailAppImage {
  width: 200px;
  height: 200px;
}
</style>
